/**
 * Copyright (c) 2013-5-2 下午3:48:04 WKM and/or its affiliates. 
 * Use is subject to license terms.
 * All rights reserved.
 */
package org.extblog.wkm.web.service.music.impl;

import java.util.Calendar;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.extblog.wkm.web.dao.music.MusicDao;
import org.extblog.wkm.web.service.AbstractService;
import org.extblog.wkm.web.service.music.MusicService;
import org.extblog.wkm.web.util.DateFormatPattern;
import org.extblog.wkm.web.vo.MusicFormView;
import org.springframework.stereotype.Controller;

/**
 * @author WKM
 * Service.java history
 * 1.WKM - 2013-5-2 - Create File
 */
@Controller
public class MusicServiceImpl extends AbstractService implements MusicService {

	/** 音乐DAO **/
	private MusicDao musicDao = null;
	
	public MusicDao getMusicDao() {
		return musicDao;
	}

	@Resource
	public void setMusicDao(MusicDao musicDao) {
		this.musicDao = musicDao;
	}

	/* (non-Javadoc)
	 * @see org.extblog.wkm.web.service.music.MusicService#removeMusicById(java.lang.String)
	 */
	@Override
	public boolean removeMusicById(String musicId) {
		// TODO Auto-generated method stub
		return false;
	}

	/* (non-Javadoc)
	 * @see org.extblog.wkm.web.service.music.MusicService#getMusics()
	 */
	@Override
	public List<Map<String, String>> getMusics() {
		// TODO Auto-generated method stub
		List<Map<String, String>> result = musicDao.selectMusics();
		log.info("共有音乐记录：" + result.size());
		return result;
	}

	/* (non-Javadoc)
	 * @see org.extblog.wkm.web.service.music.MusicService#getMusicById(java.lang.String)
	 */
	@Override
	public Map<String, String> getMusicById(String musicId) {
		// TODO Auto-generated method stub
		List<Map<String, String>> result = musicDao.selectMusicById(musicId);
		log.info("共有音乐记录：" + result.size());
		log.info("取出第一条记录：" + result.get(0));
		return result.get(0);
	}

	/* (non-Javadoc)
	 * @see org.extblog.wkm.web.service.music.MusicService#updateMusicById(org.extblog.wkm.web.vo.MusicFormView)
	 */
	@Override
	public boolean updateMusicById(MusicFormView musicFormView) {
		// TODO Auto-generated method stub
		int count = musicDao.updateBody(musicFormView);
		log.info("影响记录：" + count);
		return count >= 0;
	}

	/* (non-Javadoc)
	 * @see org.extblog.wkm.web.service.music.MusicService#addMusic(org.extblog.wkm.web.vo.MusicFormView)
	 */
	@Override
	public boolean addMusic(MusicFormView musicFormView) {
		// TODO Auto-generated method stub
		musicFormView.setMusicId(DateFormatPattern.ID + DateFormatPattern.SPLIT_CHAR + DateFormatUtils.format(Calendar.getInstance(),DateFormatPattern.DATE_TIME));
		int count = musicDao.insertMusic(musicFormView);
		log.info("影响记录：" + count);
		return count >= 0;
	}
	
	

}
